package com.alm.web.controller.alm.datatransmit;

import com.alm.common.core.domain.AjaxResult;
import com.alm.handle.core.domain.entity.rq.AlmDataTransmitConfigAddRq;
import com.alm.handle.core.domain.entity.rq.AlmDataTransmitConfigEditRq;
import com.alm.handle.core.domain.entity.rq.AlmDataTransmitConfigListRq;
import com.alm.handle.core.domain.entity.rq.EditEnabledStatusRq;
import com.alm.handle.core.domain.entity.rs.AlmDataTransmitConfigRs;
import com.alm.handle.core.domain.entity.vo.TestTransmitVO;
import com.alm.handle.service.DataTransmitService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ywy
 * @date 2024/7/17
 */
@RestController
@RequestMapping("/alm/data_transmit")
public class DataTransmitController {

    @Resource
    private DataTransmitService dataTransmitService;

    /**
     * 新增
     * @param rq
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("add")
    public AjaxResult add(@RequestBody AlmDataTransmitConfigAddRq rq) {

        int row = dataTransmitService.add(rq);
        return AjaxResult.success(row);
    }

    /**
     * 编辑
     * @param rq
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody AlmDataTransmitConfigEditRq rq) {

        int row = dataTransmitService.edit(rq);
        return  AjaxResult.success(row);
    }

    /**
     * 根据id获取详情
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {

        AlmDataTransmitConfigRs res = dataTransmitService.detail(id);
        return AjaxResult.success(res);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @DeleteMapping("/del/{id}")
    public AjaxResult del(@PathVariable("id") Long id) {

        int row = dataTransmitService.del(id);
        return AjaxResult.success(row);
    }

    /**
     * 修改启用状态
     * @param rq
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("/change_enabled_status")
    public AjaxResult changeEnabledStatus(@RequestBody EditEnabledStatusRq rq) {
        int row  = dataTransmitService.changeEnabledStatus(rq);
        return AjaxResult.success(row);
    }

    /**
     * 列表查询
     * @param rq
     * @return
     */
    @PreAuthorize("@ss.hasRole('common')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody AlmDataTransmitConfigListRq rq) {
        List<AlmDataTransmitConfigRs> res = dataTransmitService.getList(rq);
        return AjaxResult.success(res);
    }

    @PostMapping("/test")
    public AjaxResult test(@RequestBody TestTransmitVO vo) {
        dataTransmitService.test(vo);
        return AjaxResult.success();
    }


}
